/*
 * gpa_common_utils.c
 *
 *  Created on: Mar 14, 2011
 *      Author: Sharks group.
 */

#include"../image-bg-data/background.raw.c"
#include "../image-bg-data/bgPalette.c"

#include"../image-bg-data/over.raw.c"
#include "../image-bg-data/overPalette.c"

#include"../image-bg-data/welcome.raw.c"
#include "../image-bg-data/welcomePalette.c"

#include"../image-bg-data/win.raw.c"
#include "../image-bg-data/winPalette.c"

#include"../image-bg-data/credits_bg.raw.c"
#include "../image-bg-data/creditsPalette.c"

//copy memory
void gba_cpy16(u16* target,u16*source,u16 count){
	int i;
	for (i = 0; i < count; ++i) {
		target[i]=source[i];
	}
}

//load background
void loadBG() {
	int i;
	for (i = 0; i < 255; i++) {
		BGPaletteMem[i] = bgPalette_Palette[i];
	}
	for (i = 0; i < 120 * 160; i++) {
		VideoBuffer[i] = ((u16*) background_Bitmap)[i];
	}
}

//load welcome screen
void loadWelcomeScreen() {
	int i;
	for (i = 0; i < 255; i++) {
		BGPaletteMem[i] = welcomePalette_Palette[i];
	}
	for (i = 0; i < 120 * 160; i++) {
		VideoBuffer[i] = ((u16*) welcome_Bitmap)[i];
	}

}

//load win screen
void loadWinScreen() {
	int i;
	for (i = 0; i < 120 * 160; i++) {
		VideoBuffer[i] = ((u16*) win_Bitmap)[i];
	}
	for (i = 0; i < 255; i++) {
		BGPaletteMem[i] = winPalette_Palette[i];
	}
}

//load over screen
void loadOverScreen() {
	int i;
	for (i = 0; i < 120 * 160; i++) {
		VideoBuffer[i] = ((u16*) over_Bitmap)[i];
	}
	for (i = 0; i < 255; i++) {
		BGPaletteMem[i] = overPalette_Palette[i];
	}
}

//load credits screen
void loadCreditScreen() {
	int i;
	for (i = 0; i < 120 * 160; i++) {
		VideoBuffer[i] = ((u16*) credits_bg_Bitmap)[i];
	}
	for (i = 0; i < 255; i++) {
		BGPaletteMem[i] = creditsPalette_Palette[i];
	}
}

//initial sprite
void InitializeSprites() {
	int loop;
	for (loop = 0; loop < 128; loop++) {
		sprites[loop].attribute0 = 160; //y to > 159
		sprites[loop].attribute1 = 240; //x to > 239
		sprites[loop].attribute2 = 0;
	}
}

void WaitForVsync()
{
	while((volatile u16)REG_VCOUNT != 160){}
}
